/*
 * =====================================================================================
 *
 *       Filename:  node_terminal.h
 *
 *    Description:  This file contains the description for class
 *    NodeTerminal. It is used to interface with CaffCache component in manifold
 *    and talk to the node_to_iris_module class
 *
 *        Version:  1.0
 *        Created:  02/07/2011 05:00:39 PM
 *       Revision:  none
 *       Compiler:  g++/ mpicxx
 *
 *         Author:  Mitchelle Rasquinha
 *        Company:  Georgia Institute of Technology
 *
 * =====================================================================================
 */

#ifndef  NODETERMINAL_H_INC
#define  NODETERMINAL_H_INC

#include	"interfaces/irisTerminal.h"
#include	"interfaces/irisInterface.h"
#include	"kernel/clock.h"
#include	"kernel/manifold.h"
#include	"iris/data_types/mreqPkt.h"
#include	"uarch/module.h"

//extern class Clock* master_clock;
class NodeTerminal: public IrisTerminal
{
    public:
        /* ====================  LIFECYCLE  ======================================= */
        NodeTerminal ():IrisTerminal(){}
        NodeTerminal (uint nid):IrisTerminal(nid){}
        ~NodeTerminal ();

        /* ====================  Event handlers  ======================================= */
        void handle_issue_pkt_event( int inputid ); 
        void handle_issue_pkt_event( Mreq* mreq ); 
        void handle_send_credit_event( int inputid, uint64_t data ); 
        void handle_new_packet_event( int inputid, NetworkPacket* data);
        void handle_update_credit_event( int inputid, uint64_t data);

        /* ====================  Clocked funtions  ======================================= */
        void tick (void);
        void tock (void);

        /* ====================  Setup functions  ======================================= */
        void init ( void );
        void parse_config(std::map<std::string,std::string>& params);
        std::string print_stats( void ) const;

        uint ni_buffer_width;
        std::vector<bool> ni_buffers;        /* Credits for the buffers in the interface */
        uint send_buffer_id;

        // for integration with Caffcache
        Module* caffTerm;
    protected:

    private:
        uint no_nodes;
        uint no_mcs;
        std::vector<int> mc_positions;

        /* Stat variables */
        uint64_t stat_packets_in;
        uint64_t stat_packets_out;
        uint64_t stat_last_packet_out_cycle;
        uint64_t stat_last_packet_in_cycle;
        uint64_t stat_total_latency;

}; /* -----  end of class NodeTerminal  ----- */

#endif   /* ----- #ifndef NODETERMINAL_H_INC  ----- */

